def sql_value_retrival(sql_condition):
    # 初始化表名和列名列表
    table_names = []
    column_names = []

    # 遍历 sql_condition 中的所有条件
    for condition in sql_condition:
        # 提取表名和列名
        table_name = condition['table_name_origin']
        column_name = condition['column_name']

        # 如果别名为空，则使用原始表名
        table_name_alias = condition.get('table_name_alias', None)
        if not table_name_alias:
            table_name_alias = table_name  # 使用原始表名作为别名

        # 将表名和列名添加到列表中
        if table_name not in table_names:
            table_names.append(table_name)
        if column_name not in column_names:
            column_names.append(column_name)

    # 构建最终的 SQL 查询
    columns_str = ', '.join([f"`{column}`" for column in column_names])
    tables_str = ', '.join([f"`{table}`" for table in table_names])

    sql = f"""
     f"SELECT DISTINCT({columns_str}) 
     FROM {tables_str}"
    """
    return sql


if __name__ == '__main__':
    sql_condition = [
        {'table_name_alias': '航空公司航班信息表_Sheet1', 'table_name_origin': '航空公司航班信息表_Sheet1',
         'column_name': '航空公司', 'operator': 'LIKE', 'value': ['%大韩航空%']}
    ]

    # 调用函数并打印 SQL 查询
    sql_query = sql_value_retrival(sql_condition)







